import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../../common/routers/routes.dart';
import '../../../../common/widgets/o2_stateless_widget.dart';
import 'index.dart';

class AttendanceSettingPage extends GetView<AttendanceSettingController> {
  const AttendanceSettingPage({Key? key}) : super(key: key);

  static void open() {
    Get.toNamed(O2OARoutes.appAttendanceSetting);
  }

  // 主视图
  Widget _buildView(BuildContext context) {
    return ListView(
      children: [
        const SizedBox(height: 10),
        O2UI.sectionOutBox(
            Column(children: [
              Obx(() => Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Text('attendance_setting_fast_checkin_onDuty'.tr),
                      Switch(
                        value: controller.state.onDutyFastCheckInEnable,
                        onChanged: (bool value) {
                          controller.switchOnDutyFastCheckin(value);
                        },
                      )
                    ],
                  )),
              const Divider(height: 1),
              Obx(() => Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Text('attendance_setting_fast_checkin_offDuty'.tr),
                      Switch(
                        value: controller.state.offDutyFastCheckInEnable,
                        onChanged: (bool value) {
                          controller.switchOffDutyFastCheckin(value);
                        },
                      )
                    ],
                  )),
            ]),
            context),
        const SizedBox(height: 10),
        Obx(() => controller.state.aliFaceRegistration
            ? O2UI.sectionOutBox(
                O2UI.lineWidget(
                    'attendance_setting_face_registration'.tr, const SizedBox(),
                    ontap: controller.openFaceRegistration),
                context)
            : const SizedBox())
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AttendanceSettingController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(title: Text("attendance_tab_settings".tr)),
          body: SafeArea(
            child: _buildView(context),
          ),
        );
      },
    );
  }
}
